﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OgilvyOne.UKNow.DAL;
using OgilvyOne.UKNow.Model;
using System.Xml.Linq;
using OgilvyOne.UKNow.Configuration;

namespace OgilvyOne.UKNow.BLL
{
   public class AudioBLL
    {

        int langid;

        public int Langid
        {
            get { return langid; }
            set { langid = value; }
        }
        public AudioBLL(int lang_id)
        {
            Langid = lang_id;
        }
       public List<Audio> getALL()
       {
           AudioDal ad = new AudioDal(Langid);
           List<Audio> la=ad.GetALLMod();
           return la;


       }
       public bool add( Audio aud)
       {
           AudioDal ad = new AudioDal(Langid);
           return ad.Add(aud);
       }
       public bool update(Audio aud)
       {
           AudioDal ad = new AudioDal(Langid);
           return ad.Update(aud);
       }
       public bool del(int id)
       {
           AudioDal ad = new AudioDal(Langid);
           return ad.Delete(id);
       }
       public Audio toEdito(int id)
       {
           AudioDal ad = new AudioDal(Langid);
           return ad.GetAudioModsById(id);

       }
       public List<Audio>  find( string name )
       {
           AudioDal ad = new AudioDal(Langid);
           return ad.FindByNameAuthor(name);
       }
       public Audio getmodByid(int id)
       {
           return new AudioDal(Langid).GetAudioModsById(id);
       }
        private string getAudioXML(Audio aud)
       {
           XDocument Employee = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
                                    new XElement("Audio",

                                                            new XAttribute("id", aud.Id),
                                                            new XAttribute("url", aud.FilePath != null ? ConfigCacheManager.FilePath.UploadMediaPath.VirtualPath + "/" + aud.FilePath : ""),
                                                            new XAttribute("Name", aud.Name != null ? aud.Name : ""),
                                                            new XAttribute("Author", aud.Author != null ? aud.Author : ""),
                                                             new XAttribute("Description", aud.Description != null ? aud.Description : ""),
                                                            new XAttribute("Bigimg", aud.Bigimg != null ? ConfigCacheManager.FilePath.UploadImagePath.VirtualPath + "/" + aud.Bigimg : "")
                                                            
                                                            ));

           return Employee.ToString();
       }
        public string getxml()
        {
            List<Audio> lad = new AudioDal(Langid).GetALLRelaseMod();
            if (lad != null | lad.Count != 0)
            {
                StringBuilder stb = new StringBuilder();
                
                foreach (Audio aud in lad)
                {

                    stb.Append(getAudioXML(aud));
                }
                stb.Insert(0, String.Format("<Audios count='{0}'>", lad.Count));
                stb.Insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
                stb.Append("</Audios>");
                return stb.ToString();
            }
            else
            {
                return "";
            }
        }
        public List<Audio> getALLRele()
        {
            return new AudioDal(Langid).GetALLRelaseMod();
        }
        public List<Audio> getALLnoRele()
        {
            return new AudioDal(Langid).GetALLnoRelaseMod();
        }

    }
}
